package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

public class code110_easy {

    static class Solution {
        public boolean isBalanced(TreeNode root) {
            return helper(root) == -1;
        }

        public int helper(TreeNode root){
            if(root==null){
                return 0;
            }
            int left = helper(root.left);
            int right = helper(root.right);
            if(left==-1||right==-1){
                return -1;
            }
            if(left-right>1||right-left>1){
                return -1;
            }
            return Integer.max(left, right)+1;
        }
    }

    public static void main(String[] args){
    }
}
